/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prototype.vaadin;

import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.TwinColSelect;
import com.vaadin.ui.VerticalLayout;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
 * @author Cmd
 */
public class TwinColumnSelect extends VerticalLayout
        implements Property.ValueChangeListener {
    /**.
     * @param selectedOptions
     */
    private List<String> selectedOptions;
    /**.
     * @param selected
     */
    private String selected;

    /**.
     * Constructor
     */
    public TwinColumnSelect() {
        selectedOptions = new ArrayList<String>();
        selected = null;
        setSpacing(true);

        TwinColSelect l = new TwinColSelect();
        l.addItem("No element");
        l.setWidth("600px");

        addComponent(l);
    }

    /**.
     * @return selected
     */
    public String getSelected() {
        return selected;
    }

    /**.
     * @param menuitems
     */
    public TwinColumnSelect(final Elements menuitems) {
        setSpacing(true);

        TwinColSelect l = new TwinColSelect();

        for (Element a : menuitems) {
            l.addItem(a.html().replace("&amp;", "&"));
        }
        final int value = 8;
        l.setRows(value);
        l.setNullSelectionAllowed(true);
        l.setMultiSelect(true);
        l.setImmediate(true);
        l.addListener(this);
        l.setWidth("650px");
        addComponent(l);
    }

    @Override
    /**.
     * Shows a notification when a selection is made
     * @param event
     */
    public void valueChange(final ValueChangeEvent event) {
        if (!event.getProperty().toString().equals("[]")) {
            getWindow().showNotification("Selected option : "
                    + event.getProperty());
            setSelected(event.getProperty().toString());
        } else {
            setSelected("");
        }
    }

    /**.
     * @return selectedOptions
     */
    public List<String> getSelectedOptions() {
        return selectedOptions;
    }

    /**.
     * @param selectedOptions
     */
    public void setSelectedOptions(List<String> selectedOptions) {
        this.selectedOptions = selectedOptions;
    }

    /**.
     * @param selected
     */
    public void setSelected(String selected) {
        this.selected = selected;
    }
}